package com.example.myapplication

import android.os.Bundle
import android.view.View
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.view.WindowCompat
import com.example.myapplication.ui.components.NavHostApp
import com.example.myapplication.ui.screens.MainFarme
import com.example.myapplication.ui.theme.MyApplicationTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // 处理状态栏不透明和底部导航栏遮盖内容问题
        // 使用Accompanist插件
        // 系统自带状态栏会浮动,内容会出现在系统自带导航栏的上层(会出Bug)
          WindowCompat.setDecorFitsSystemWindows(window, false)
        // 不使用Accompanist插件情况下
//        // 处理不同机型状态栏不透明和导航栏遮盖内容
//        // 让底部导航栏不在遮盖内容,还需要SYSTEM_UI_FLAG_LAYOUT_STABLE来稳定布局
//        window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
//        // 导航栏颜色设置
//        window.statusBarColor = Color.Transparent.value.toInt()

        // 获取状态栏高度
//        var statusBarHeight = 0
//        val resourceId = resources.getIdentifier("start_bar_height", "dimen", "android")
//        // resourceId > 0表示获取到了id
//        if (resourceId > 0) {
//            statusBarHeight = resources.getDimensionPixelSize(resourceId)
//        }


        setContent {
            MyApplicationTheme {
                // A surface container using the 'background' color from the theme
                Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colors.background) {
                    NavHostApp()
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String) {
    Text(text = "Hello $name!")
}
